package com.lcxw.hxzbapi.controller.membercontroller;

import com.alibaba.fastjson.JSONObject;
import com.lcxw.hxzbapi.entity.requestBean.GetFriendInfoReq;
import com.lcxw.hxzbapi.entity.requestBean.RequestParamBasic;
import com.lcxw.hxzbapi.entity.response.RichLevelInfo;
import java.util.Map;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.lcxw.hxzbapi.entity.response.Response;

@RestController
@CrossOrigin
@Slf4j
@RequestMapping("api/user")
public class LevelController {

    @Resource
    MemberRealization memberRealization;

    /**
     * 1、获取用户的所有等级接口
     */
    @PostMapping("/getLevel")
    public Response getLevel(@RequestBody JSONObject requestParams) {
        long userId = Long.parseLong(requestParams.getString("userId"));
        log.info("user {} get his all levels.", userId);
        Map data;
        try {
            data = memberRealization.getLevels(userId);
        } catch (Exception e) {
            return Response.dbFail(log, "get user levels");
        }
        return Response.ok(data);
    }

    /**
     * 2、获取财富等级信息，用于个人中心展示
     */
    @PostMapping("/richLevel/get")
    public Response getRichLevel(@RequestBody @Validated GetFriendInfoReq requestBody) {
        long userId = Long.parseLong(requestBody.getFriendId());
        RichLevelInfo data = memberRealization.getRichLevelInfo(userId);
        return Response.ok(data);
    }

}
